package com.gmail.blackdog1987.carcare.network.request.builder;

import android.content.Context;

import com.gmail.blackdog1987.carcare.Constant;
import com.gmail.blackdog1987.carcare.network.request.RequestBuilder;
import com.gmail.blackdog1987.carcare.util.DeviceUtils;
import com.gmail.blackdog1987.carcare.util.LogUtil;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;

public class CarsaleListRequestBuilder extends RequestBuilder {

	private static final String TAG = CarsaleListRequestBuilder.class.getSimpleName();
	private int order;
	private int pageindex;
	private int pagesize;
	private int type;

	@Override
	public RequestParams buildRquest() {
		RequestParams params = new RequestParams();
		params.put("order", String.valueOf(order));
		params.put("type", String.valueOf(type));
		params.put("pageindex", String.valueOf(pageindex));
		params.put("pagesize", String.valueOf(pagesize));
		return params;
	}
	

	@Override
	public void postJsonRequest(Context context, AsyncHttpResponseHandler handler) {

		RequestParams params = buildRquest();
		
		AsyncHttpClient client = new AsyncHttpClient();
		client.setTimeout(Constant.TIMEOUT);
		client.setUserAgent(DeviceUtils.OS.getName());
		
		client.post(Constant.Action.CARSALELIST	, params, handler);
		LogUtil.d(TAG, "post : " + params);
	}
	
	public CarsaleListRequestBuilder setType(int type) {
		this.type = type;
		return this;
	}


	public CarsaleListRequestBuilder setOrder(int order) {
		this.order = order;
		return this;
	}


	public CarsaleListRequestBuilder setPageindex(int pageindex) {
		this.pageindex = pageindex;
		return this;
	}


	public CarsaleListRequestBuilder setPagesize(int pagesize) {
		this.pagesize = pagesize;
		return this;
	}

}
